package com.xiaoge.libraryuse.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.xiaoge.basedevlibrary.base.GuoBaseBackActivity;
import com.xiaoge.basedevlibrary.http.GuoBaseResponseBean;
import com.xiaoge.basedevlibrary.http.HttpUtils;
import com.xiaoge.basedevlibrary.imageload.ImageUtils;
import com.xiaoge.libraryuse.R;
import com.xiaoge.libraryuse.bean.HttpBean;

public class HttpActivity extends GuoBaseBackActivity {

    private TextView content;
    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_http);
        initView();
        initData();
    }

    private void initData() {
        // 请求的url
        String url = "http://gank.io/api/data/Android/10/1";
        // 请求完成的接口回调
        HttpUtils.NetResponseListener listener = new HttpUtils.NetResponseListener() {
            @Override
            public void onSuccess(GuoBaseResponseBean response, int requestCode) {
                HttpBean bean = (HttpBean) response;
                content.setText(bean.getResults().get(0).getDesc());
                ImageUtils.getInstance().load(iv,"https://ws1.sinaimg.cn/large/610dc034gy1fi678xgq1ij20pa0vlgo4.jpg");
            }

            @Override
            public void onFailed(int requestCode) {

            }
        };
        // 请求接口
        HttpUtils.getInstance().get(url, null, 100, HttpBean.class, listener);
    }

    private void initView() {
        content = (TextView) findViewById(R.id.content);
        iv = (ImageView) findViewById(R.id.iv);
    }
}
